package cn.wolfcode.trip.api.controller;


import cn.wolfcode.trip.base.domain.Finance;
import cn.wolfcode.trip.base.service.IFinanceService;

import cn.wolfcode.trip.base.util.JsonResult;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@RestController
@RequestMapping("finances")
public class FinanceController {

    @Autowired
    private IFinanceService financeService;

    /*
    * 用户借款的接口
    * */
    @PostMapping
    public JsonResult insert(Finance finance){
        JsonResult json = new JsonResult();
        try {
            financeService.insert(finance);
        } catch (Exception e) {
            e.printStackTrace();
            json.mark(e.getMessage());
        }
        return json;
    }

    @PostMapping("{id}/{money}")
    public JsonResult updata(@PathVariable Long id,@PathVariable BigDecimal money){
        JsonResult json = new JsonResult();
        try {
            financeService.update(id,money);
        } catch (Exception e) {
            e.printStackTrace();
            json.mark(e.getMessage());
        }
        return json;
    }

    @GetMapping("{id}")
    public Finance get(@PathVariable Long id){
        return financeService.get(id);
    }

}
